home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / intuition / freeclass.c < prev    next >
C/C++ Source or Header  |  1996-09-12  |  3KB  |  112 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: freeclass.c,v 1.1 1996/08/28 17:55:34 digulla Exp $
  4.     $Log: freeclass.c,v $
  5.     Revision 1.1  1996/08/28 17:55:34  digulla
  6.     Proportional gadgets
  7.     BOOPSI
  8.  
  9.  
  10.     Desc:
  11.     Lang: english
  12. */
  13. #include <clib/exec_protos.h>
  14. #include "intuition_intern.h"
  15.  
  16. /*****************************************************************************
  17.  
  18.     NAME */
  19.     #include <intuition/classes.h>
  20.     #include <clib/intuition_protos.h>
  21.  
  22.     __AROS_LH1(BOOL, FreeClass,
  23.  
  24. /*  SYNOPSIS */
  25.     __AROS_LHA(struct IClass *, classPtr, A0),
  26.  
  27. /*  LOCATION */
  28.     struct IntuitionBase *, IntuitionBase, 119, Intuition)
  29.  
  30. /*  FUNCTION
  31.     Only for class implementatores.
  32.  
  33.     Tries to free a class which has been created with MakeClass() in the
  34.     first place. This will not succeed in all cases: Classes which
  35.     still have living objects or which are still beeing used by subclasses
  36.     can't simply be freed. In this case this call will fail.
  37.  
  38.     Public classes will always be removed with RemoveClass() no matter
  39.     if FreeClass() would succeed or not. This gurantees that after the
  40.     call to FreeClass() no new objects can be created.
  41.  
  42.     If you have a pointer to allocated memory in cl_UserData, you must
  43.     make a copy of that pointer, call FreeClass() and if the call
  44.     succeeded, you may free the memory. If you don't follow these rules,
  45.     you might end up with a class which is partially freed.
  46.  
  47.     INPUTS
  48.     classPtr - The pointer you got from MakeClass().
  49.  
  50.     RESULT
  51.     FALSE if the class couldn't be freed at this time. This can happen
  52.     either if there are still objects from this class or if the class
  53.     is used a SuperClass of at least another class.
  54.  
  55.     TRUE if the class could be freed. You must not use classPtr after
  56.     that.
  57.  
  58.     NOTES
  59.     *Always* calls RemoveClass().
  60.  
  61.     EXAMPLE
  62.     // Free a public class with dynamic memory in cl_UserD
  63.  
  64.     int freeMyClass (Class * cl)
  65.     {
  66.         struct MyPerClassData * mpcd;
  67.  
  68.         mpcd = (struct MyPerClassData *)cl->cl_UserData;
  69.  
  70.         if (FreeClass (cl)
  71.         {
  72.         FreeMem (mpcd, sizeof (struct MyPerClassData));
  73.         return (TRUE);
  74.         }
  75.  
  76.         return (FALSE);
  77.     }
  78.  
  79.     BUGS
  80.  
  81.     SEE ALSO
  82.  
  83.     INTERNALS
  84.     MakeClass(), "Basic Object-Oriented Programming System for Intuition"
  85.     and "boopsi Class Reference" Dokument.
  86.  
  87.     HISTORY
  88.     29-10-95    digulla automatically created from
  89.                 intuition_lib.fd and clib/intuition_protos.h
  90.  
  91. *****************************************************************************/
  92. {
  93.     __AROS_FUNC_INIT
  94.     __AROS_BASE_EXT_DECL(struct IntuitionBase *,IntuitionBase)
  95.  
  96.     /* Make sure no one creates another object from this class. For private
  97.     classes, this call does nothing. */
  98.     RemoveClass (classPtr);
  99.  
  100.     if (!classPtr->cl_SubclassCount && !classPtr->cl_ObjectCount)
  101.     {
  102.     classPtr->cl_Super->cl_SubclassCount --;
  103.  
  104.     FreeMem (classPtr, sizeof (Class));
  105.  
  106.     return (TRUE);
  107.     }
  108.  
  109.     return (FALSE);
  110.     __AROS_FUNC_EXIT
  111. } /* FreeClass */
  112.